package com.jilintongyi.jlcrtvu.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import org.hibernate.annotations.Table;
import org.hibernate.annotations.Where;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(appliesTo = "sys_role", comment = "系统角色表")
public class SysRole extends BaseEntity {
	@ManyToMany(mappedBy = "roles", fetch = FetchType.LAZY) // 由user的roles维护，懒加载
	@Where(clause = "deleted=false")
	@JsonIgnore
	private List<SysUser> users;

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "SysRoleAuthority", joinColumns = @JoinColumn(name = "roleId"), inverseJoinColumns = @JoinColumn(name = "authorityId"))
	@Where(clause = "deleted=false")
	private List<SysAuthority> authorities;

	@Column(nullable = false, columnDefinition = "varchar(255) comment '角色名称'")
	private String roleName;

	public List<SysUser> getUsers() {
		return users;
	}

	public void setUsers(List<SysUser> users) {
		this.users = users;
	}

	public List<SysAuthority> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(List<SysAuthority> authorities) {
		this.authorities = authorities;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
}
